package com.spic.business.detector.controller;

import com.spic.business.detector.domain.HkSmokeDetector;
import com.spic.business.detector.mapper.DoorIndexCodeMapper;
import com.spic.business.detector.service.IHkSmokeDetectorService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 海康烟感报警Controller
 *
 * @author spic
 * @date 2022-04-15
 */
@RestController
@RequestMapping("/detector")
public class HkSmokeDetectorController extends BaseController
{
    @Autowired
    private IHkSmokeDetectorService hkSmokeDetectorService;

    @Autowired
    private DoorIndexCodeMapper doorIndexCodeMapper;

    /**
     * 查询海康烟感报警列表
     */
    @PreAuthorize(hasPermi = "business:detector:list")
    @GetMapping("/list")
    public AjaxResult list(HkSmokeDetector hkSmokeDetector)
    {
        List<HkSmokeDetector> list = hkSmokeDetectorService.selectHkSmokeDetectorList(hkSmokeDetector);
        return AjaxResult.success(list);
    }

    @GetMapping("/doorIndexCodeList")
    public  AjaxResult doorIndexCodeList(){
        return AjaxResult.success(doorIndexCodeMapper.selectDoorIndexCodeList());
    }
    /**
     * 导出海康烟感报警列表
     */
    @PreAuthorize(hasPermi = "business:detector:export")
    @Log(title = "海康烟感报警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HkSmokeDetector hkSmokeDetector) throws IOException
    {
        List<HkSmokeDetector> list = hkSmokeDetectorService.selectHkSmokeDetectorList(hkSmokeDetector);
        ExcelUtil<HkSmokeDetector> util = new ExcelUtil<HkSmokeDetector>(HkSmokeDetector.class);
        util.exportExcel(response, list, "海康烟感报警数据");
    }

    /**
     * 获取海康烟感报警详细信息
     */
    @PreAuthorize(hasPermi = "business:detector:query")
    @GetMapping(value = "/{indexCode}")
    public AjaxResult getInfo(@PathVariable("indexCode") String indexCode)
    {
        return AjaxResult.success(hkSmokeDetectorService.selectHkSmokeDetectorByIndexCode(indexCode));
    }

    /**
     * 新增海康烟感报警
     */
    @PreAuthorize(hasPermi = "business:detector:add")
    @Log(title = "海康烟感报警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HkSmokeDetector hkSmokeDetector)
    {
        return toAjax(hkSmokeDetectorService.insertHkSmokeDetector(hkSmokeDetector));
    }

    /**
     * 修改海康烟感报警
     */
    @PreAuthorize(hasPermi = "business:detector:edit")
    @Log(title = "海康烟感报警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HkSmokeDetector hkSmokeDetector)
    {
        return toAjax(hkSmokeDetectorService.updateHkSmokeDetector(hkSmokeDetector));
    }

    /**
     * 删除海康烟感报警
     */
    @PreAuthorize(hasPermi = "business:detector:remove")
    @Log(title = "海康烟感报警", businessType = BusinessType.DELETE)
	@DeleteMapping("/{indexCodes}")
    public AjaxResult remove(@PathVariable String[] indexCodes)
    {
        return toAjax(hkSmokeDetectorService.deleteHkSmokeDetectorByIndexCodes(indexCodes));
    }
}
